﻿package com.lin.utils;




import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.google.gson.JsonArray;
import com.lin.bean.PingLunBean;
import com.lin.bean.ZanList;
import com.ly.quickdev.library.utils.JsonUtils;
import com.yunfeng.supercall.activity.BaseActivity;
import com.yunfeng.supercall.app.AppContext;
import com.yunfeng.supercall.bean.AdsBean;
import com.yunfeng.supercall.bean.FriendsShareBean;
import com.yunfeng.supercall.bean.FriendsShareZanBean;
import com.yunfeng.supercall.bean.LevelBean;
import com.yunfeng.supercall.bean.LevelColorBean;
import com.yunfeng.supercall.bean.MyCircleBean;
import com.yunfeng.supercall.bean.NewSuperFriendsBean;
import com.yunfeng.supercall.bean.RecentCallsBean;
import com.yunfeng.supercall.bean.SuperFriendsBean;
import com.yunfeng.supercall.bean.UserBean;

import android.R.integer;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;


public class Session {

	private String mLogin;


	public LocalDb getmLocalDb() {
		return mLocalDb;
	}

	public void setmLocalDb(LocalDb mLocalDb) {
		this.mLocalDb = mLocalDb;
	}

	public boolean ismOffline() {
		return mOffline;
	}

	public void setmOffline(boolean mOffline) {
		this.mOffline = mOffline;
	}


	UserBean mUserBean;
	public UserBean getmUserBean() {

		String result = SharePreferenceUtil.getInstance().getUserInfo(mContext);
		if(mUserBean == null)
			if(!TextUtils.isEmpty(result)) {
				mUserBean = JsonUtils.parse(
						result.substring(1, result.length() - 1), UserBean.class);
			}
		return mUserBean;
	}

	public void setmUserBean(UserBean mUserBean) {
		this.mUserBean = mUserBean;
	}


	private String mPassword;
	private String mNickname;
	private String mAvatar;
	private String mUid;
	private static Session sSession;	
	private IO mIo;
	private boolean mIsConnected;
	private Context mContext;

	private boolean mAuthenticated;
	private boolean mDisconnectWithFaultAuthentification;
	LocalDb mLocalDb;
	private boolean mOffline;


	/** This is used to get notified of asynchronous request reply */
	public interface ResultReceiver<P> {
		void onResult(boolean last, P args);
	}

	public enum SignupResult {
		LOGIN_UNAVAILABLE,
		SUCCESS,
		IO_ERROR
	}

	public enum ApplyResult {
		Apply_UNAVAILABLE,
		SUCCESS,
		IO_ERROR
	}

	public enum ApplyGroupResult {
		SUCCESS,
		Apply_UNAVAILABLE,
		IO_ERROR
	}

	public enum ZanResult {
		SUCCESS,
		Zan_UNAVAILABLE,
		IO_ERROR
	}


	public enum AuthenticationResult {
		AUTHENTICATED,
		UNAUTHORIZED,
		IO_ERROR
	}

	private Session() {}

	public static Session getSession() {
		if(sSession==null) {
			sSession=new Session();
		}

		return sSession;
	}

	public void init(Context context, boolean devmode) {
		if (mLocalDb == null) {
			mLocalDb = new LocalDb(context, devmode);
		}
		if (mIo == null) {
			mIo = new IO(mLocalDb, devmode, context);
		}
		mIsConnected = true;
		mDisconnectWithFaultAuthentification = false;

		mContext = context;
		//prefetch all categories and products
		//		prefetchProducts();

	}






	public void signup(final ResultReceiver<SignupResult> result_receiver) {
		new AsyncTask<Void, Void, SignupResult>() {
			@Override
			protected SignupResult doInBackground(Void... params) {
				try {


					JSONObject mJSONObject = mIo.signup(mLogin, mPassword, mNickname);
					if(mJSONObject != null) {
						try {

							if(mJSONObject.getInt("status") == 1) {
								JSONObject mDataObject = mJSONObject.getJSONObject("data");
								mNickname = mDataObject.getString("UserName");  
								mAvatar = mDataObject.getString("HeadImg");
								mUid = mDataObject.getString("id");

								return SignupResult.SUCCESS;
							} else {
								return SignupResult.LOGIN_UNAVAILABLE;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return SignupResult.IO_ERROR;		

			}

			@Override
			protected void onPostExecute(SignupResult result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}

	/*(返回值:1=超友,2=关注,3=粉丝,0=陌生人)*/
	public void getUserLogin2(final Context context ,final String phone, final String pass, final ResultReceiver<String> result_receiver) {
		new AsyncTask<Void, Void, String>() {
			@Override
			protected String doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_phone", phone);
						jsonObject.put("i_pass", pass);
						Log.i("tag", jsonObject.toString());
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.getUserLogin2(phone, pass, jsonObject.toString());

					if(mJSONObject != null) {
						String resultObj = mJSONObject.getString("Data");
						try {
							if(resultObj != null) {
								//								resultObj
								mUserBean = JsonUtils.parse(
										resultObj.substring(1, resultObj.length() - 1), UserBean.class);
								return resultObj;
							} else {
								return null;	
							}

						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return null;	

			}

			@Override
			protected void onPostExecute(String result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}


	/*(返回值:1=超友,2=关注,3=粉丝,0=陌生人)*/
	public void changeRelation(final Context context ,final int userid, final int friendid, final int i_relation, final ResultReceiver<SignupResult> result_receiver) {
		new AsyncTask<Void, Void, SignupResult>() {
			@Override
			protected SignupResult doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("userid", userid);
						jsonObject.put("friendid", friendid);
						jsonObject.put("i_relation", i_relation);
						Log.i("tag", jsonObject.toString());
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.changeRelation(userid, friendid, i_relation, jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {

								return SignupResult.SUCCESS;
							} else {
								return SignupResult.IO_ERROR;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return SignupResult.IO_ERROR;	

			}

			@Override
			protected void onPostExecute(SignupResult result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}


	/*(返回值:1=超友,2=关注,3=粉丝,0=陌生人)*/
	public void addFriendApp(final Context context ,final int userid, final int friendid, final ResultReceiver<SignupResult> result_receiver) {
		new AsyncTask<Void, Void, SignupResult>() {
			@Override
			protected SignupResult doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_userid", userid);
						jsonObject.put("i_otherid", friendid);

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.addFriendApp(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {

								return SignupResult.SUCCESS;
							} else {
								return SignupResult.IO_ERROR;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return SignupResult.IO_ERROR;	

			}

			@Override
			protected void onPostExecute(SignupResult result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}

	//1 是短信  2是手机 
	public void SendPushMsg(final Context context ,final String content ,final int MsgType, final String ToUserPhone, final String AlertMsg, final ResultReceiver<Integer> result_receiver) {
		new AsyncTask<Void, Void, Integer>() {
			@Override
			protected Integer doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("ToUserPhone", ToUserPhone);
						jsonObject.put("MsgType", MsgType);
						jsonObject.put("AlertMsg", AlertMsg);
						jsonObject.put("MsgData", content);

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.SendPushMsg(content, MsgType, ToUserPhone, AlertMsg, jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("code") == 1011) {
								return -1;
							} else if(mJSONObject.getInt("code") == 0) {
								return 1;
							}
							/*if(mJSONObject.length() > 0) {
								return 1;
							} else {
								return -1;	
							}*/
						} catch(NullPointerException e) {
							return -1;
						}
					}
				} catch(Exception e) {

				}
				return -1;	

			}

			@Override
			protected void onPostExecute(Integer result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}
	
	public void getOtherCounter(final Context context ,final int i_userid ,final int i_callid, final ResultReceiver<Integer> result_receiver) {
		new AsyncTask<Void, Void, Integer>() {
			@Override
			protected Integer doInBackground(Void... params) {
				try {
					JSONObject mJSONObject = mIo.getOtherCounter(i_userid, i_callid);
					Log.i("tag", mJSONObject + "");
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 1011) {
								return -1;
							} else if(mJSONObject.getInt("Code") == 0) {
								return 1;
							}
							/*if(mJSONObject.length() > 0) {
								return 1;
							} else {
								return -1;	
							}*/
						} catch(NullPointerException e) {
							return -1;
						}
					}
				} catch(Exception e) {

				}
				return -1;	

			}

			@Override
			protected void onPostExecute(Integer result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}

	
	
	public void setCreateCallRecord(final Context context ,final String i_userid ,final String i_otherid, final ResultReceiver<Integer> result_receiver) {
		new AsyncTask<Void, Void, Integer>() {
			@Override
			protected Integer doInBackground(Void... params) {
				try {
					JSONObject mJSONObject = mIo.setCreateCallRecord(i_userid, i_otherid);
					Log.i("tag", mJSONObject + "");
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 1011) {
								return -1;
							} else if(mJSONObject.getInt("Code") == 0) {
								return 1;
							}
							/*if(mJSONObject.length() > 0) {
								return 1;
							} else {
								return -1;	
							}*/
						} catch(NullPointerException e) {
							return -1;
						}
					}
				} catch(Exception e) {

				}
				return -1;	

			}

			@Override
			protected void onPostExecute(Integer result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}
	
	public void setUpdateCallRecord(final Context context ,final int i_callid ,final int i_userid, final ResultReceiver<Integer> result_receiver) {
		new AsyncTask<Void, Void, Integer>() {
			@Override
			protected Integer doInBackground(Void... params) {
				try {
					JSONObject mJSONObject = mIo.setUpdateCallRecord(i_callid, i_userid);
					Log.i("tag", mJSONObject + "");
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 1011) {
								return -1;
							} else if(mJSONObject.getInt("Code") == 0) {
								return 1;
							}
							/*if(mJSONObject.length() > 0) {
								return 1;
							} else {
								return -1;	
							}*/
						} catch(NullPointerException e) {
							return -1;
						}
					}
				} catch(Exception e) {

				}
				return -1;	

			}

			@Override
			protected void onPostExecute(Integer result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}

	public void getCallRecord(final Context context ,final String i_otherid, final ResultReceiver<Integer> result_receiver) {
		new AsyncTask<Void, Void, Integer>() {
			@Override
			protected Integer doInBackground(Void... params) {
				try {
					JSONObject mJSONObject = mIo.getCallRecord(i_otherid);
					Log.i("tag", mJSONObject + "");
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 1011) {
								return -1;
							} else if(mJSONObject.getInt("Code") == 0) {
								return 1;
							}
							/*if(mJSONObject.length() > 0) {
								return 1;
							} else {
								return -1;	
							}*/
						} catch(NullPointerException e) {
							return -1;
						}
					}
				} catch(Exception e) {

				}
				return -1;	

			}

			@Override
			protected void onPostExecute(Integer result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}

	public void setOverCallRecord(final Context context ,final String i_callid, final ResultReceiver<Integer> result_receiver) {
		new AsyncTask<Void, Void, Integer>() {
			@Override
			protected Integer doInBackground(Void... params) {
				try {
					JSONObject mJSONObject = mIo.setOverCallRecord(i_callid);
					Log.i("tag", mJSONObject + "");
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("code") == 1011) {
								return -1;
							} else if(mJSONObject.getInt("code") == 0) {
								return 1;
							}
							/*if(mJSONObject.length() > 0) {
								return 1;
							} else {
								return -1;	
							}*/
						} catch(NullPointerException e) {
							return -1;
						}
					}
				} catch(Exception e) {

				}
				return -1;	

			}

			@Override
			protected void onPostExecute(Integer result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}


	

	//1 是短信  2是手机 
	public void SendPushMsg2(final Context context ,final int MsgType, final String ToUserPhone, final String AlertMsg, final ResultReceiver<Integer> result_receiver) {
		new AsyncTask<Void, Void, Integer>() {
			@Override
			protected Integer doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("ToUserPhone", ToUserPhone);
						jsonObject.put("MsgType", MsgType);
						jsonObject.put("AlertMsg", AlertMsg);

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.SendPushMsg2(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {
								return 1;
							} else {
								return -1;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return -1;	

			}

			@Override
			protected void onPostExecute(Integer result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}


	/*(返回值:1=超友,2=关注,3=粉丝,0=陌生人)*/
	public void setShareState(final Context context ,final String userid, final String friendid, final String i_sta, final ResultReceiver<Integer> result_receiver) {
		new AsyncTask<Void, Void, Integer>() {
			@Override
			protected Integer doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_userid", userid);
						jsonObject.put("i_friendid", friendid);
						jsonObject.put("i_sta", i_sta);

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.setShareState(userid + "", friendid + "", i_sta + "");
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getBoolean("Data") == true) {
								//								JSONObject jsoObject = new JSONObject(mJSONObject.getString("Data").replace("[", "").replace("]", ""));
								return 1;
							} else {
								return -1;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return -1;	

			}

			@Override
			protected void onPostExecute(Integer result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}

	public void setShareStateUser(final Context context ,final String userid, final String friendid, final String i_sta, final ResultReceiver<Integer> result_receiver) {
		new AsyncTask<Void, Void, Integer>() {
			@Override
			protected Integer doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_userid", userid);
						jsonObject.put("i_friendid", friendid);
						jsonObject.put("i_sta", i_sta);

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.setShareStateUser(userid + "", friendid + "", i_sta + "");
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getBoolean("Data") == true) {
								//								JSONObject jsoObject = new JSONObject(mJSONObject.getString("Data").replace("[", "").replace("]", ""));
								return 1;
							} else {
								return -1;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return -1;	

			}

			@Override
			protected void onPostExecute(Integer result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}

	public void SetStore(final Context context ,final String userid, final String shareid, final ResultReceiver<Integer> result_receiver) {
		new AsyncTask<Void, Void, Integer>() {
			@Override
			protected Integer doInBackground(Void... params) {
				try {
					JSONObject mJSONObject = mIo.SetStore(userid + "", shareid + "");
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getBoolean("Data") == true) {
								//								JSONObject jsoObject = new JSONObject(mJSONObject.getString("Data").replace("[", "").replace("]", ""));
								return 1;
							} else {
								return 0;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return -1;	

			}

			@Override
			protected void onPostExecute(Integer result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}

	public void setFriendState(final Context context ,final String userid, final String friendid, final String i_sta, final ResultReceiver<Integer> result_receiver) {
		new AsyncTask<Void, Void, Integer>() {
			@Override
			protected Integer doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_userid", userid);
						jsonObject.put("i_friendid", friendid);
						jsonObject.put("i_sta", i_sta);

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.setFriendState(userid + "", friendid + "", i_sta + "");
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getBoolean("Data") == true) {
								//								JSONObject jsoObject = new JSONObject(mJSONObject.getString("Data").replace("[", "").replace("]", ""));
								return 1;
							} else {
								return -1;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return -1;	

			}

			@Override
			protected void onPostExecute(Integer result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}



	public void setPinglunReply(final Context context ,final String userid, final String i_shareid,  final String i_content, final String i_lat,final String i_lng, final String i_replyid, final ResultReceiver<Integer> result_receiver) {
		new AsyncTask<Void, Void, Integer>() {
			@Override
			protected Integer doInBackground(Void... params) {
				try {
					JSONObject mJSONObject = mIo.setPinglunReply(userid + "", i_shareid + "", i_content, i_lat, i_lng, i_replyid);
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getBoolean("Data") == true) {
								return 1;
							} else {
								return -1;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return -1;	

			}

			@Override
			protected void onPostExecute(Integer result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}


	public void friendGetSearchDetail(final Context context ,final String userid, final String friendid, final String i_sta, final ResultReceiver<Integer> result_receiver) {
		new AsyncTask<Void, Void, Integer>() {
			@Override
			protected Integer doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_userid", userid);
						jsonObject.put("i_friendid", friendid);
						jsonObject.put("i_sta", i_sta);

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.setFriendState(userid + "", friendid + "", i_sta + "");
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getBoolean("Data") == true) {
								//								JSONObject jsoObject = new JSONObject(mJSONObject.getString("Data").replace("[", "").replace("]", ""));
								return 1;
							} else {
								return -1;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return -1;	

			}

			@Override
			protected void onPostExecute(Integer result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}



	/*(返回值:1=超友,2=关注,3=粉丝,0=陌生人)*/
	public void AddFriendSweep(final Context context ,final String userid, final String friendid, final ResultReceiver<Integer> result_receiver) {
		new AsyncTask<Void, Void, Integer>() {
			@Override
			protected Integer doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_userid", userid);
						jsonObject.put("i_friendid", friendid);
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.AddFriendSweep(userid + "", friendid + "");
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getBoolean("Data") == true) {
								//								JSONObject jsoObject = new JSONObject(mJSONObject.getString("Data").replace("[", "").replace("]", ""));
								return 1;
							} else {
								return -1;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return -1;	

			}

			@Override
			protected void onPostExecute(Integer result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}


	/*(返回值:1=超友,2=关注,3=粉丝,0=陌生人)*/
	public void checkRelation(final Context context ,final int userid, final int friendid, final ResultReceiver<Integer> result_receiver) {
		new AsyncTask<Void, Void, Integer>() {
			@Override
			protected Integer doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_userid", userid);
						jsonObject.put("i_friendid", friendid);
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.checkRelation(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {
								JSONObject jsoObject = new JSONObject(mJSONObject.getString("Data").replace("[", "").replace("]", ""));
								return jsoObject.getInt("status");
							} else {
								return -1;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return -1;	

			}

			@Override
			protected void onPostExecute(Integer result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}

	/*(返回值:1=超友,2=关注,3=粉丝,0=陌生人)*/
	public void addSharePinglun(final Context context ,final int i_userid, final int i_shareid, final String content, final double i_lat, final double i_lng, final ResultReceiver<Integer> result_receiver) {
		new AsyncTask<Void, Void, Integer>() {
			@Override
			protected Integer doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_userid", i_userid);
						jsonObject.put("i_shareid", i_shareid);
						jsonObject.put("i_content", content);
						jsonObject.put("i_lat", i_lat);
						jsonObject.put("i_lng", i_lng);

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.addSharePinglun(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {
								JSONObject jsoObject = new JSONObject(mJSONObject.getString("Data").replace("[", "").replace("]", ""));
								return 1;
							} else {
								return -1;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					} 
				} catch(Exception e) {

				}
				return -1;	

			}

			@Override
			protected void onPostExecute(Integer result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}



	public void addFollower(final Context context ,final int userid, final int otheruserid, final ResultReceiver<SignupResult> result_receiver) {
		new AsyncTask<Void, Void, SignupResult>() {
			@Override
			protected SignupResult doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_userid", userid);
						jsonObject.put("i_friendid", otheruserid);
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.addFollower(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {

								return SignupResult.SUCCESS;
							} else {
								return SignupResult.LOGIN_UNAVAILABLE;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return SignupResult.IO_ERROR;	

			}

			@Override
			protected void onPostExecute(SignupResult result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}



	public void loginLog(final Context context ,final int userid, final String device, final ResultReceiver<SignupResult> result_receiver) {
		new AsyncTask<Void, Void, SignupResult>() {
			@Override
			protected SignupResult doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_userid", userid);
						jsonObject.put("i_device", device);

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.loginLog(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {

								return SignupResult.SUCCESS;
							} else {
								return SignupResult.LOGIN_UNAVAILABLE;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return SignupResult.IO_ERROR;	

			}

			@Override
			protected void onPostExecute(SignupResult result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}


	public void addGuanzhu(final Context context ,final int userid, final int otheruserid, final ResultReceiver<SignupResult> result_receiver) {
		new AsyncTask<Void, Void, SignupResult>() {
			@Override
			protected SignupResult doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_userid", userid);
						jsonObject.put("i_otherid", otheruserid);
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.addGuanzhu(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {

								return SignupResult.SUCCESS;
							} else {
								return SignupResult.LOGIN_UNAVAILABLE;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return SignupResult.IO_ERROR;	

			}

			@Override
			protected void onPostExecute(SignupResult result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}


	public void acceptFriendApy(final Context context ,final int userid, final int apyid, final int state, final ResultReceiver<SignupResult> result_receiver) {
		new AsyncTask<Void, Void, SignupResult>() {
			@Override
			protected SignupResult doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_userid", userid);
						jsonObject.put("i_apyid", apyid);
						jsonObject.put("i_state", state);
						Log.i("tag", jsonObject.toString());
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.acceptFriendApy(jsonObject.toString());
					Log.i("tag", mJSONObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {

								return SignupResult.SUCCESS;
							} else {
								return SignupResult.LOGIN_UNAVAILABLE;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					} 
				} catch(Exception e) {

				}
				return SignupResult.IO_ERROR;	

			}

			@Override
			protected void onPostExecute(SignupResult result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}




	public void callHistoryDel(final Context context , final String callid,final String user1,final String user2, final ResultReceiver<SignupResult> result_receiver) {
		new AsyncTask<Void, Void, SignupResult>() {
			@Override
			protected SignupResult doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_callid", callid);
						jsonObject.put("i_user1", user1);
						jsonObject.put("i_user2", user2);
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.changePass(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {

								return SignupResult.SUCCESS;
							} else {
								return SignupResult.LOGIN_UNAVAILABLE;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return SignupResult.IO_ERROR;	

			}

			@Override
			protected void onPostExecute(SignupResult result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}




	public void changePass(final Context context , final String phone,final String newpass,final String key, final ResultReceiver<SignupResult> result_receiver) {
		new AsyncTask<Void, Void, SignupResult>() {
			@Override
			protected SignupResult doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_phone", phone);
						jsonObject.put("i_newpass", newpass);
						jsonObject.put("i_key", "更改密码");
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.changePass(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {

								return SignupResult.SUCCESS;
							} else {
								return SignupResult.LOGIN_UNAVAILABLE;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return SignupResult.IO_ERROR;	

			}

			@Override
			protected void onPostExecute(SignupResult result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}

	public void getFriendApyList(final Context context , final int userid,final int pagenum, final ResultReceiver<ArrayList<NewSuperFriendsBean>> result_receiver) {
		{
			new AsyncTask<Void, Void, ArrayList<NewSuperFriendsBean>>() {
				@Override
				protected ArrayList<NewSuperFriendsBean> doInBackground(Void... params) {
					try {
						JSONObject jsonObject = getBaseParams(context);
						try {
							jsonObject.put("i_userid", userid);
							jsonObject.put("i_pagenum", pagenum);
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						JSONObject mJSONObject = mIo.getFriendApyList(jsonObject.toString());
						Log.i("tag", mJSONObject.toString());
						if(mJSONObject != null) {
							try {

								if(mJSONObject.getInt("Code") == 0) {
									String mDataObject = mJSONObject.getString("Data");

									ArrayList<NewSuperFriendsBean> mRealFriends = new ArrayList<NewSuperFriendsBean>( JsonUtils.parseList(
											mDataObject.toString(), NewSuperFriendsBean.class));

									return mRealFriends;
								} else {
									return null;	
								}

							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (NullPointerException ep) {
								return null;
							}
						} 
					} catch(Exception e) {

					}
					return null;		

				}

				@Override
				protected void onPostExecute(ArrayList<NewSuperFriendsBean> result) {
					result_receiver.onResult(true, result);
				}
			}.execute((Void)null);
		}
	}


	public void getSearchFriend(final Context context , final int userid, final int i_key, final int i_page, final int i_size, final ResultReceiver<SuperFriendsBean> result_receiver) {
		{
			new AsyncTask<Void, Void, SuperFriendsBean>() {
				@Override
				protected SuperFriendsBean doInBackground(Void... params) {
					try {
						JSONObject mJSONObject = mIo.getSearchFriend(userid + "", i_key + "", i_page + "", i_size + "");
						//					Log.i("supercall", mJSONObject.toString());
						if(mJSONObject != null) {
							try {

								if(mJSONObject.getInt("Code") == 0) {
									String mDataObject = mJSONObject.getString("Data");

									SuperFriendsBean mSuperFriends = JsonUtils.parse(
											mDataObject.substring(1, mDataObject.length() - 1),
											SuperFriendsBean.class);

									return mSuperFriends;
								} else {
									return null;	
								}

							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (NullPointerException ep) {
								return null;
							}
						} 
					} catch(Exception e) {

					}
					return null;		

				}

				@Override
				protected void onPostExecute(SuperFriendsBean result) {
					result_receiver.onResult(true, result);
				}
			}.execute((Void)null);
		}
	}


	public void getVoidObject(final Context context , final String userid, final String vo_id, final ResultReceiver<SuperFriendsBean> result_receiver) {
		{
			new AsyncTask<Void, Void, SuperFriendsBean>() {
				@Override
				protected SuperFriendsBean doInBackground(Void... params) {
					try {
						JSONObject mJSONObject = mIo.getVoidObject(userid + "", vo_id + "");
						//					Log.i("supercall", mJSONObject.toString());
						if(mJSONObject != null) {
							try {

								if(mJSONObject.getInt("Code") == 0) {
									String mDataObject = mJSONObject.getString("Data");
									JSONObject jsonObject = new JSONObject(mDataObject.substring(1, mDataObject.length() - 1));
									SuperFriendsBean mSuperFriends = new SuperFriendsBean();
									mSuperFriends.setSex(jsonObject.getInt("sex"));
									mSuperFriends.setPhone(jsonObject.getString("phone"));
									mSuperFriends.setTel(jsonObject.getString("tel"));

									mSuperFriends.setUserid(jsonObject.getInt("userid"));
									mSuperFriends.setLng(jsonObject.getDouble("lng"));
									mSuperFriends.setType(jsonObject.getInt("type"));
									mSuperFriends.setPhoto(jsonObject.getString("photo"));
									mSuperFriends.setNick_name(jsonObject.getString("nick_name"));
									mSuperFriends.setSucolor(jsonObject.getInt("sucolor"));
									mSuperFriends.setOnlineday(jsonObject.getString("onlineday"));
									mSuperFriends.setLevel(jsonObject.getInt("level"));
									mSuperFriends.setSuid(jsonObject.getString("suid"));
									mSuperFriends.setAddress(jsonObject.getString("address"));
//									mSuperFriends.setReal_name(jsonObject.getString("real_name"));
									mSuperFriends.setVo_id(jsonObject.getString("vo_id"));
									mSuperFriends.setNote(jsonObject.getString("note"));
									mSuperFriends.setLat(jsonObject.getDouble("lat"));



									return mSuperFriends;
								} else {
									return null;	
								}

							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (NullPointerException ep) {
								return null;
							}
						} 
					} catch(Exception e) {

					}
					return null;		

				}

				@Override
				protected void onPostExecute(SuperFriendsBean result) {
					result_receiver.onResult(true, result);
				}
			}.execute((Void)null);
		}
	}

	public void getAllCount(final Context context , final int userid, final ResultReceiver<SuperFriendsBean> result_receiver) {
		{
			new AsyncTask<Void, Void, SuperFriendsBean>() {
				@Override
				protected SuperFriendsBean doInBackground(Void... params) {
					try {
						JSONObject jsonObject = getBaseParams(context);
						try {
							jsonObject.put("i_userid", userid);
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						JSONObject mJSONObject = mIo.getAllCount(userid,  jsonObject.toString());
						//					Log.i("supercall", mJSONObject.toString());
						if(mJSONObject != null) {
							try {

								if(mJSONObject.getInt("Code") == 0) {
									String mDataObject = mJSONObject.getString("Data");

									SuperFriendsBean mSuperFriends = JsonUtils.parse(
											mDataObject.substring(1, mDataObject.length() - 1),
											SuperFriendsBean.class);

									return mSuperFriends;
								} else {
									return null;	
								}

							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (NullPointerException ep) {
								return null;
							}
						} 
					} catch(Exception e) {

					}
					return null;		

				}

				@Override
				protected void onPostExecute(SuperFriendsBean result) {
					result_receiver.onResult(true, result);
				}
			}.execute((Void)null);
		}
	}

	public void getFriendDetailNew(final Context context , final int userid,final int friendid, final ResultReceiver<SuperFriendsBean> result_receiver) {
		{
			new AsyncTask<Void, Void, SuperFriendsBean>() {
				@Override
				protected SuperFriendsBean doInBackground(Void... params) {
					SuperFriendsBean mSuperFriends = new SuperFriendsBean();
					try {
						JSONObject jsonObject = getBaseParams(context);
						try {
							jsonObject.put("userid", userid);
							jsonObject.put("friendid", friendid);
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						JSONObject mJSONObject = mIo.getFriendDetailNew(userid, friendid, jsonObject.toString());
						//					Log.i("supercall", mJSONObject.toString());
						if(mJSONObject != null) {
							try {

								if(mJSONObject.getInt("Code") == 0) {
									String mDataObject = mJSONObject.getString("Data");
									mDataObject = mDataObject.substring(1, mDataObject.length()-1);

									JSONObject jo = new JSONObject(mDataObject);

									mSuperFriends.setSex(jo.getInt("sex"));
									//								mSuperFriends.setTel(jo.getString("tel"));
									mSuperFriends.setUserid(jo.getInt("userid"));
									mSuperFriends.setLng(jo.getInt("lng"));
									mSuperFriends.setType(jo.getInt("type"));
									mSuperFriends.setPhoto(jo.getString("photo"));
									mSuperFriends.setNick_name(jo.getString("nick_name"));
									//								mSuperFriends.seth(jo.getString("onlineday"));
									mSuperFriends.setLevel(jo.getInt("level"));
									mSuperFriends.setSuid(jo.getString("suid"));
									JSONArray jsonArray = new JSONArray(jo.getString("shareimgs"));
									ArrayList<String> mListImg = new ArrayList<String>();
									int cpt2 = 0 ;
									int size = jsonArray.length();
									while(cpt2 < size) {
										JSONObject jsonobject = jsonArray.getJSONObject(cpt2);
										String img = jsonobject.getString("img");
										String[] imgList = img.split(";");
										//									mListImg.add(img);
										int size2 = imgList.length;
										int cpt3 = 0;
										while(cpt3 < size2) {
											mListImg.add(imgList[cpt3]);
											cpt3 ++;
										}
										cpt2 ++;
									}
									mSuperFriends.setmListImg(mListImg);
									mSuperFriends.setAddress(jo.getString("address"));
									//								mSuperFriends.setReal_name(jo.getString("real_name"));
									mSuperFriends.setVo_id(jo.getString("vo_id"));
									mSuperFriends.setNote(jo.getString("note"));
									mSuperFriends.setLat(jo.getDouble("lat"));



									//								mSuperFriends.setTel(mJSONObject.getString("tel"));
								} else {
									return null;	
								}

							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (NullPointerException ep) {
								return null;
							}
						} 
					} catch(Exception e) {

					}
					return mSuperFriends;

				}

				@Override
				protected void onPostExecute(SuperFriendsBean result) {
					result_receiver.onResult(true, result);
				}
			}.execute((Void)null);
		}
	}
	public void getShareListNew(final Context context , final int userid,final int pagenum, final ResultReceiver<ArrayList<FriendsShareBean>> result_receiver) {
		{
			new AsyncTask<Void, Void, ArrayList<FriendsShareBean>>() {
				@Override
				protected ArrayList<FriendsShareBean> doInBackground(Void... params) {
					try {
						JSONObject jsonObject = getBaseParams(context);
						try {
							jsonObject.put("i_userid", userid);
							jsonObject.put("i_pagenum", pagenum);
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						JSONObject mJSONObject = mIo.getShareListNew(jsonObject.toString());
						if(mJSONObject != null) {
							try {

								if(mJSONObject.getInt("Code") == 0) {
									String mDataObject = mJSONObject.getString("Data");

									ArrayList<FriendsShareBean> mRealFriends = new ArrayList<FriendsShareBean>( JsonUtils.parseList(
											mDataObject.toString(), FriendsShareBean.class));

									return mRealFriends;
								} else {
									return null;	
								}

							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (NullPointerException ep) {
								return null;
							}
						} 
					} catch(Exception e) {

					}
					return null;		

				}

				@Override
				protected void onPostExecute(ArrayList<FriendsShareBean> result) {
					result_receiver.onResult(true, result);
				}
			}.execute((Void)null);
		}
	}


	public void getQuanziList(final Context context , final int userid,final int pagenum, final ResultReceiver<ArrayList<MyCircleBean>> result_receiver) {
		{
			new AsyncTask<Void, Void, ArrayList<MyCircleBean>>() {
				@Override
				protected ArrayList<MyCircleBean> doInBackground(Void... params) {
					try {
						JSONObject jsonObject = getBaseParams(context);
						try {
							jsonObject.put("i_userid", userid);
							jsonObject.put("i_pagenum", pagenum);
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						JSONObject mJSONObject = mIo.getQuanziList(jsonObject.toString());
						if(mJSONObject != null) {
							try {

								if(mJSONObject.getInt("Code") == 0) {
									String mDataObject = mJSONObject.getString("Data");

									ArrayList<MyCircleBean> mRealFriends = new ArrayList<MyCircleBean>( JsonUtils.parseList(
											mDataObject.toString(), MyCircleBean.class));

									return mRealFriends;
								} else {
									return null;	
								}

							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (NullPointerException ep) {
								return null;
							}
						} 
					} catch(Exception e) {

					}
					return null;		

				}

				@Override
				protected void onPostExecute(ArrayList<MyCircleBean> result) {
					result_receiver.onResult(true, result);
				}
			}.execute((Void)null);
		}
	}

	public void getLevelList(final Context context , final int userid,final int pagenum, final ResultReceiver<ArrayList<LevelBean>> result_receiver) {
		{
			new AsyncTask<Void, Void, ArrayList<LevelBean>>() {
				@Override
				protected ArrayList<LevelBean> doInBackground(Void... params) {
					try {
						JSONObject jsonObject = getBaseParams(context);
						try {
							jsonObject.put("i_userid", userid);
							jsonObject.put("i_pagenum", pagenum);
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						JSONObject mJSONObject = mIo.getLevelList(jsonObject.toString());
						if(mJSONObject != null) {
							try {

								if(mJSONObject.getInt("Code") == 0) {
									String mDataObject = mJSONObject.getString("Data");

									ArrayList<LevelBean> mRealFriends = new ArrayList<LevelBean>( JsonUtils.parseList(
											mDataObject.toString(), LevelBean.class));

									return mRealFriends;
								} else {
									return null;	
								}

							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (NullPointerException ep) {
								return null;
							}
						} 
					} catch(Exception e) {

					}
					return null;		

				}

				@Override
				protected void onPostExecute(ArrayList<LevelBean> result) {
					result_receiver.onResult(true, result);
				}
			}.execute((Void)null);
		}
	}


	public void getSuColorList(final Context context , final int userid, final ResultReceiver<ArrayList<LevelColorBean>> result_receiver) {
		{
			new AsyncTask<Void, Void, ArrayList<LevelColorBean>>() {
				@Override
				protected ArrayList<LevelColorBean> doInBackground(Void... params) {
					try {
						JSONObject jsonObject = getBaseParams(context);
						try {
							jsonObject.put("i_userid", userid);
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						JSONObject mJSONObject = mIo.getSuColorList(jsonObject.toString());
						if(mJSONObject != null) {
							try {

								if(mJSONObject.getInt("Code") == 0) {
									String mDataObject = mJSONObject.getString("Data");

									ArrayList<LevelColorBean> mRealFriends = new ArrayList<LevelColorBean>( JsonUtils.parseList(
											mDataObject.toString(), LevelColorBean.class));

									return mRealFriends;
								} else {
									return null;	
								}

							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (NullPointerException ep) {
								return null;
							}
						} 
					} catch(Exception e) {

					}
					return null;		

				}

				@Override
				protected void onPostExecute(ArrayList<LevelColorBean> result) {
					result_receiver.onResult(true, result);
				}
			}.execute((Void)null);
		}
	}

	public void getSysAd(final Context context , final int userid, final ResultReceiver<ArrayList<AdsBean>> result_receiver) {
		{
			new AsyncTask<Void, Void, ArrayList<AdsBean>>() {
				@Override
				protected ArrayList<AdsBean> doInBackground(Void... params) {
					try {
						JSONObject jsonObject = getBaseParams(context);
						try {
							jsonObject.put("i_userid", userid);
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						JSONObject mJSONObject = mIo.getSysAd(jsonObject.toString());
						if(mJSONObject != null) {
							try {

								if(mJSONObject.getInt("Code") == 0) {
									String mDataObject = mJSONObject.getString("Data");

									ArrayList<AdsBean> mRealFriends = new ArrayList<AdsBean>( JsonUtils.parseList(
											mDataObject.toString(), AdsBean.class));

									return mRealFriends;
								} else {
									return null;	
								}

							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (NullPointerException ep) {
								return null;
							}
						} 
					} catch(Exception e) {

					}
					return null;		

				}

				@Override
				protected void onPostExecute(ArrayList<AdsBean> result) {
					result_receiver.onResult(true, result);
				}
			}.execute((Void)null);
		}
	}


	public void getGuanzhuList(final Context context , final String userid,final String pagenum, final ResultReceiver<ArrayList<SuperFriendsBean>> result_receiver) {
		{
			new AsyncTask<Void, Void, ArrayList<SuperFriendsBean>>() {
				@Override
				protected ArrayList<SuperFriendsBean> doInBackground(Void... params) {
					try {
						JSONObject jsonObject = getBaseParams(context);
						try {
							jsonObject.put("i_userid", userid);
							jsonObject.put("i_pagenum", pagenum);
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						JSONObject mJSONObject = mIo.getGuanzhuList(jsonObject.toString());
						if(mJSONObject != null) {
							try {

								if(mJSONObject.getInt("Code") == 0) {
									String mDataObject = mJSONObject.getString("Data");

									ArrayList<SuperFriendsBean> mRealFriends = new ArrayList<SuperFriendsBean>( JsonUtils.parseList(
											mDataObject.toString(), SuperFriendsBean.class));
									Collections.sort(mRealFriends);

									return mRealFriends;
								} else {
									return null;	
								}

							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (NullPointerException ep) {
								return null;
							}
						} 
					} catch(Exception e) {

					}
					return null;		

				}

				@Override
				protected void onPostExecute(ArrayList<SuperFriendsBean> result) {
					result_receiver.onResult(true, result);
				}
			}.execute((Void)null);
		}
	}




	public void checkLocalAddressBook(final Context context , final String phones, final ResultReceiver<ArrayList<SuperFriendsBean>> result_receiver) {
		{
			new AsyncTask<Void, Void, ArrayList<SuperFriendsBean>>() {
				@Override
				protected ArrayList<SuperFriendsBean> doInBackground(Void... params) {
					try {


						JSONObject jsonObject = getBaseParams(context);
						try {
							jsonObject.put("i_phones", phones);
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						JSONObject mJSONObject = mIo.checkLocalAddressBook(jsonObject.toString());
						if(mJSONObject != null) {
							try {

								if(mJSONObject.getInt("Code") == 0) {
									String mDataObject = mJSONObject.getString("Data");

									ArrayList<SuperFriendsBean> mRealFriends = new ArrayList<SuperFriendsBean>( JsonUtils.parseList(
											mDataObject.toString(), SuperFriendsBean.class));
									Collections.sort(mRealFriends);

									return mRealFriends;
								} else {
									return null;	
								}

							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (NullPointerException ep) {
								return null;
							}
						} 
					} catch(Exception e) {

					}
					return null;		

				}

				@Override
				protected void onPostExecute(ArrayList<SuperFriendsBean> result) {
					result_receiver.onResult(true, result);
				}
			}.execute((Void)null);
		}
	}
	
	



	public void getNoGroupFriendList(final Context context , final int pagenum, final ResultReceiver<ArrayList<SuperFriendsBean>> result_receiver) {
		new AsyncTask<Void, Void, ArrayList<SuperFriendsBean>>() {
			@Override
			protected ArrayList<SuperFriendsBean> doInBackground(Void... params) {
				try {
					try {
						JSONObject jsonObject = getBaseParams(context);
						try {
							jsonObject.put("i_pagenum", pagenum);
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						JSONObject mJSONObject = mIo.getNoGroupFriendList(jsonObject.toString());
						if(mJSONObject != null) {
							try {
								if(mJSONObject.getInt("Code") == 0) {
									String mDataObject = mJSONObject.getString("Data");

									ArrayList<SuperFriendsBean> mRealFriends = new ArrayList<SuperFriendsBean>( JsonUtils.parseList(
											mDataObject.toString(), SuperFriendsBean.class));
									Collections.sort(mRealFriends);

									return mRealFriends;
								} else {
									return null;	
								}

							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} 
						}
					} catch(NullPointerException e) {

					}
				} catch(Exception e) {

				}
				return null;		

			}

			@Override
			protected void onPostExecute(ArrayList<SuperFriendsBean> result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}




	public void getFensiList(final Context context , final int pagenum, final int userid, final ResultReceiver<ArrayList<SuperFriendsBean>> result_receiver) {
		new AsyncTask<Void, Void, ArrayList<SuperFriendsBean>>() {
			@Override
			protected ArrayList<SuperFriendsBean> doInBackground(Void... params) {
				try {


					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_pagenum", pagenum);
						jsonObject.put("i_userid", userid);

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.getFensiList(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {
								String mDataObject = mJSONObject.getString("Data");

								ArrayList<SuperFriendsBean> mRealFriends = new ArrayList<SuperFriendsBean>( JsonUtils.parseList(
										mDataObject.toString(), SuperFriendsBean.class));
								Collections.sort(mRealFriends);

								return mRealFriends;
							} else {
								return null;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					} 
				} catch(Exception e) {

				}
				return null;		

			}

			@Override
			protected void onPostExecute(ArrayList<SuperFriendsBean> result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}

	public void getGuanzhuList(final Context context , final int pagenum, final int userid, final ResultReceiver<ArrayList<SuperFriendsBean>> result_receiver) {
		new AsyncTask<Void, Void, ArrayList<SuperFriendsBean>>() {
			@Override
			protected ArrayList<SuperFriendsBean> doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_pagenum", pagenum);
						jsonObject.put("i_userid", userid);

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.getGuanzhuList(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {
								String mDataObject = mJSONObject.getString("Data");

								ArrayList<SuperFriendsBean> mRealFriends = new ArrayList<SuperFriendsBean>( JsonUtils.parseList(
										mDataObject.toString(), SuperFriendsBean.class));
								Collections.sort(mRealFriends);

								return mRealFriends;
							} else {
								return null;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					} 
				} catch(Exception e) {

				}
				return null;		

			}

			@Override
			protected void onPostExecute(ArrayList<SuperFriendsBean> result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}


	public void getEnSuperChatList(final Context context , final int pagenum, final double lat, final double longi, final ResultReceiver<ArrayList<SuperFriendsBean>> result_receiver) {
		new AsyncTask<Void, Void, ArrayList<SuperFriendsBean>>() {
			@Override
			protected ArrayList<SuperFriendsBean> doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_pagenum", pagenum);
						jsonObject.put("i_lat", lat);
						jsonObject.put("i_lng", longi);

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.getEnSuperChatList(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {
								String mDataObject = mJSONObject.getString("Data");

								ArrayList<SuperFriendsBean> mRealFriends = new ArrayList<SuperFriendsBean>( JsonUtils.parseList(
										mDataObject.toString(), SuperFriendsBean.class));
								Collections.sort(mRealFriends);

								return mRealFriends;
							} else {
								return null;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					} 
				} catch(Exception e) {

				}
				return null;		

			}

			@Override
			protected void onPostExecute(ArrayList<SuperFriendsBean> result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}

	public void GetEnSuperChatList(final Context context , final int pagenum, final double lat, final double longi,final ResultReceiver<ArrayList<SuperFriendsBean>> result_receiver) {
		new AsyncTask<Void, Void, ArrayList<SuperFriendsBean>>() {
			@Override
			protected ArrayList<SuperFriendsBean> doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_pagenum", pagenum);
						jsonObject.put("i_lat", lat);
						jsonObject.put("i_lng", longi);
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.GetEnSuperChatList(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {
								String mDataObject = mJSONObject.getString("Data");

								ArrayList<SuperFriendsBean> mRealFriends = new ArrayList<SuperFriendsBean>( JsonUtils.parseList(
										mDataObject.toString(), SuperFriendsBean.class));
								Collections.sort(mRealFriends);

								return mRealFriends;
							} else {
								return null;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					} 
				} catch(Exception e) {

				}
				return null;		

			}

			@Override
			protected void onPostExecute(ArrayList<SuperFriendsBean> result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}


	public void getNearUserList(final Context context , final int pagenum, final double lat, final double longi,final ResultReceiver<ArrayList<SuperFriendsBean>> result_receiver) {
		new AsyncTask<Void, Void, ArrayList<SuperFriendsBean>>() {
			@Override
			protected ArrayList<SuperFriendsBean> doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_pagenum", pagenum);
						jsonObject.put("i_lat", lat);
						jsonObject.put("i_lng", longi);
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.getNearUserList(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {
								String mDataObject = mJSONObject.getString("Data");

								ArrayList<SuperFriendsBean> mRealFriends = new ArrayList<SuperFriendsBean>( JsonUtils.parseList(
										mDataObject.toString(), SuperFriendsBean.class));
								Collections.sort(mRealFriends);

								return mRealFriends;
							} else {
								return null;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					} 
				} catch(Exception e) {

				}
				return null;		

			}

			@Override
			protected void onPostExecute(ArrayList<SuperFriendsBean> result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}

	public synchronized void  getFriendList(final Context context , final int userid, final int pageNum, final ResultReceiver<ArrayList<SuperFriendsBean>> result_receiver) {
		new AsyncTask<Void, Void, ArrayList<SuperFriendsBean>>() {
			@Override
			protected ArrayList<SuperFriendsBean> doInBackground(Void... params) {
				JSONObject jsonObject = getBaseParams(context);
				try {


					try {
						jsonObject.put("i_userid", userid);
						jsonObject.put("i_pagenum", pageNum);
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.getFriendList(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {
								String mDataObject = mJSONObject.getString("Data");

								ArrayList<SuperFriendsBean> mRealFriends = new ArrayList<SuperFriendsBean>( JsonUtils.parseList(
										mDataObject.toString(), SuperFriendsBean.class));
								Collections.sort(mRealFriends);

								return mRealFriends;
							} else {
								return null;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return null;		

			}

			@Override
			protected void onPostExecute(ArrayList<SuperFriendsBean> result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}



	public synchronized void getCallHistory(final Context context , final int pagenum, final ResultReceiver<ArrayList<RecentCallsBean>> result_receiver) {
		new AsyncTask<Void, Void, ArrayList<RecentCallsBean>>() {
			@Override
			protected ArrayList<RecentCallsBean> doInBackground(Void... params) {
				try {


					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_pagenum", pagenum);
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

					JSONObject mJSONObject = mIo.getCallHistory(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {
								String mDataObject = mJSONObject.getString("Data");

								ArrayList<RecentCallsBean> mDataList = new ArrayList<RecentCallsBean>( JsonUtils.parseList(
										mDataObject.toString(), RecentCallsBean.class));
								Collections.sort(mDataList);

								return mDataList;
							} else {
								return null;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return null;		

			}

			@Override
			protected void onPostExecute(ArrayList<RecentCallsBean> result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}


	public void GetStore(final Context context , final int userid, final String i_page, final String i_num, final ResultReceiver<ArrayList<FriendsShareBean>> result_receiver) {
		new AsyncTask<Void, Void, ArrayList<FriendsShareBean>>() {
			private String post;

			@Override
			protected ArrayList<FriendsShareBean> doInBackground(Void... params) {
				ArrayList<FriendsShareBean> mDataList = new ArrayList<FriendsShareBean>(); 
				try {
					try {

						JSONObject mJSONObject = mIo.GetStore(userid + "", i_num + "", i_page + "");
						if(mJSONObject != null) {
							try {
								if(mJSONObject.getInt("Code") == 0) {
									JSONArray mArray = mJSONObject.getJSONArray("Data");
									int size = mArray.length();
									int cpt = 0;
									while (cpt < size) {
										JSONObject mJSONItem = mArray.getJSONObject(cpt);
										FriendsShareBean mFriendsShareBean = new FriendsShareBean();
										mFriendsShareBean.setImg(mJSONItem.getString("img"));
										mFriendsShareBean.setShareid(mJSONItem.getInt("shareid"));
										mFriendsShareBean.setLng(mJSONItem.getDouble("lng"));
										mFriendsShareBean.setLat(mJSONItem.getDouble("lat"));
										mFriendsShareBean.setContent(mJSONItem.getString("content"));
										mFriendsShareBean.setPhoto(mJSONItem.getString("photo"));
										mFriendsShareBean.setNick_name(mJSONItem.getString("nick_name"));
										mFriendsShareBean.setCreatetime(mJSONItem.getString("createtime"));
										//										mFriendsShareBean.setSuColor(mJSONItem.getInt("sucolor"));
										mFriendsShareBean.setZannum(mJSONItem.getString("zannum"));
										mFriendsShareBean.setPinglunnum(mJSONItem.getString("pinglunnum"));
										mFriendsShareBean.setUserid(Integer.parseInt(mJSONItem.getString("userid")));
										cpt ++;
										mDataList.add(mFriendsShareBean);

									}
									return mDataList;



								} else {
									return null;	
								}

							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} 
						} 
					} catch(NullPointerException e) {

					}
				} catch(Exception e) {

				}
				return null;

			}

			@Override
			protected void onPostExecute(ArrayList<FriendsShareBean> result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}

	public void getShareListNew(final Context context , final int userid, final int typeid, final int zannum, final int plnum, final int pagenum, final ResultReceiver<ArrayList<FriendsShareBean>> result_receiver) {
		new AsyncTask<Void, Void, ArrayList<FriendsShareBean>>() {
			private String post;

			@Override
			protected ArrayList<FriendsShareBean> doInBackground(Void... params) {
				ArrayList<FriendsShareBean> mDataList = new ArrayList<FriendsShareBean>(); 
				try {
					try {


						JSONObject jsonObject = getBaseParams(context);
						try {
							jsonObject.put("pagenum", pagenum);
							jsonObject.put("userid", userid);
							jsonObject.put("zannum", zannum);
							jsonObject.put("plnum", plnum);
							jsonObject.put("typeid", typeid);

							post = "userid=" + userid + "&typeid="+ typeid + "&pagenum=" +pagenum + "&zannum=" + zannum +"&plnum=" + plnum;

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

						JSONObject mJSONObject = mIo.GetShareListNewURL(userid, typeid, zannum,  plnum,  pagenum, post);
						if(mJSONObject != null) {
							try {


								if(mJSONObject.getInt("Code") == 0) {
									JSONArray mArray = mJSONObject.getJSONArray("Data");
									int size = mArray.length();
									int cpt = 0;
									while (cpt < size) {
										JSONObject mJSONItem = mArray.getJSONObject(cpt);
										FriendsShareBean mFriendsShareBean = new FriendsShareBean();
										mFriendsShareBean.setImg(mJSONItem.getString("img"));
										mFriendsShareBean.setShareid(mJSONItem.getInt("shareid"));
										mFriendsShareBean.setLng(mJSONItem.getDouble("lng"));
										mFriendsShareBean.setLat(mJSONItem.getDouble("lat"));
										mFriendsShareBean.setContent(mJSONItem.getString("content"));
										mFriendsShareBean.setPhoto(mJSONItem.getString("photo"));
										mFriendsShareBean.setNick_name(mJSONItem.getString("nick_name"));
										mFriendsShareBean.setCreatetime(mJSONItem.getString("createtime"));
										mFriendsShareBean.setSuColor(mJSONItem.getInt("sucolor"));
										mFriendsShareBean.setZannum(mJSONItem.getString("zannum"));
										mFriendsShareBean.setPinglunnum(mJSONItem.getString("pinglunnum"));
										mFriendsShareBean.setUserid(Integer.parseInt(mJSONItem.getString("userid")));
										String ping = mJSONItem.getString("pinglunlist");
										if(ping.length() > 3) {
											JSONArray jsonPinglunList = new JSONArray(mJSONItem.getString("pinglunlist"));

											int cpt2 = 0;
											int size2 = jsonPinglunList.length();
											ArrayList<PingLunBean> mList = new ArrayList<PingLunBean>();
											while(cpt2 < size2) {
												JSONObject mJSONItem2 = jsonPinglunList.getJSONObject(cpt2);
												PingLunBean pingLunBean = new PingLunBean();
												pingLunBean.setContent(mJSONItem2.getString("content"));
												pingLunBean.setCreatetime(mJSONItem2.getString("createtime"));
												pingLunBean.setLat(mJSONItem2.getString("lat"));
												pingLunBean.setLng(mJSONItem2.getString("lng"));
												pingLunBean.setNick_name(mJSONItem2.getString("nick_name"));
												pingLunBean.setPhoto(mJSONItem2.getString("photo"));
												pingLunBean.setUserid(mJSONItem2.getString("userid"));
												try {
													pingLunBean.setReplyid(mJSONItem2.getInt("replyid"));
												} catch(Exception e) {

												}
												
												pingLunBean.setId(mJSONItem2.getInt("id"));
												
												JSONArray replyList = mJSONItem2.getJSONArray("replylist");
												int cpt3 = 0;
												int size3 = replyList.length();
												while (cpt3 < size3) {
													JSONObject mJSONItem3 = replyList.getJSONObject(cpt3);
													PingLunBean pingLunBean2 = new PingLunBean();
													pingLunBean2.setContent(mJSONItem3.getString("content"));
													pingLunBean2.setCreatetime(mJSONItem3.getString("createtime"));
													pingLunBean2.setLat(mJSONItem3.getString("lat"));
													pingLunBean2.setLng(mJSONItem3.getString("lng"));
													pingLunBean2.setNick_name(mJSONItem3.getString("nick_name"));
													pingLunBean2.setPhoto(mJSONItem3.getString("photo"));
													pingLunBean2.setUserid(mJSONItem3.getString("userid"));
													pingLunBean2.setSubreplyid(mJSONItem3.getInt("subreplyid"));
													pingLunBean2.setReplyname(pingLunBean.getNick_name());
													try {
														pingLunBean2.setReplyid(mJSONItem3.getInt("replyid"));
													} catch(Exception e) {

													}
													pingLunBean2.setId(mJSONItem3.getInt("id"));
													mList.add(pingLunBean2);
													cpt3 ++;

												}

												mList.add(pingLunBean);
												cpt2 ++;
											}
											mFriendsShareBean.setJsonPinglunList(mList);
										}
										try {
											String zan = mJSONItem.getString("zanlist");
											if(zan.length() > 3) {
												JSONArray jsonZanlist = new JSONArray(mJSONItem.getString("zanlist"));

												int cpt3 = 0;
												int size3 = jsonZanlist.length();
												ArrayList<ZanList> mZanList = new ArrayList<ZanList>();
												while(cpt3 < size3) {
													JSONObject mJSONItem2 = jsonZanlist.getJSONObject(cpt3);
													ZanList mZan = new ZanList();
													mZan.setNickName(mJSONItem2.getString("nick_name"));
													mZan.setPhoto(mJSONItem2.getString("photo"));
													mZanList.add(mZan);
													cpt3 ++;
												}
												mFriendsShareBean.setmZanList(mZanList);
											}		
										} catch (JSONException e) {
											// TODO Auto-generated catch block
											e.printStackTrace();
										} 
										cpt ++;
										mDataList.add(mFriendsShareBean);

									}




								} else {
									return null;	
								}

							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} 
						} 
					} catch(NullPointerException e) {

					}
				} catch(Exception e) {

				}
				return mDataList;

			}

			@Override
			protected void onPostExecute(ArrayList<FriendsShareBean> result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}


	public void getShareList(final Context context , final int pagenum, final int i_otherid, final ResultReceiver<ArrayList<FriendsShareBean>> result_receiver) {
		new AsyncTask<Void, Void, ArrayList<FriendsShareBean>>() {
			@Override
			protected ArrayList<FriendsShareBean> doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_pagenum", pagenum);
						jsonObject.put("i_otherid", i_otherid);

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

					JSONObject mJSONObject = mIo.getShareList(jsonObject.toString());
					//				Log.i("SuperCall", mJSONObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {
								String mDataObject = mJSONObject.getString("Data");

								ArrayList<FriendsShareBean> mDataList = new ArrayList<FriendsShareBean>( JsonUtils.parseList(
										mDataObject.toString(), FriendsShareBean.class));

								return mDataList;
							} else {
								return null;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					} 
				} catch(Exception e) {

				}
				return null;		

			}

			@Override
			protected void onPostExecute(ArrayList<FriendsShareBean> result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}



	public void getFriendDetailNew1(final Context context , final int i_userid, final int i_friendid, final ResultReceiver<SuperFriendsBean> result_receiver) {
		new AsyncTask<Void, Void, SuperFriendsBean>() {
			@Override
			protected SuperFriendsBean doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_userid", i_userid);
						jsonObject.put("i_friendid", i_friendid);
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.getFriendDetailNew(i_userid, i_friendid, jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {
								String mDataObject = mJSONObject.getString("Data");

								SuperFriendsBean mSuperFriends = JsonUtils.parse(
										mDataObject.substring(1, mDataObject.length() - 1),
										SuperFriendsBean.class);

								return mSuperFriends;
							} else {
								return null;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					} 
				} catch(Exception e) {

				}
				return null;		

			}

			@Override
			protected void onPostExecute(SuperFriendsBean result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}

	public void searchUser(final Context context , final String phone, final ResultReceiver<SuperFriendsBean> result_receiver) {
		new AsyncTask<Void, Void, SuperFriendsBean>() {
			@Override
			protected SuperFriendsBean doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_key", phone);
						jsonObject.put("i_type", 0);
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.searchUser(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {
								String mDataObject = mJSONObject.getString("Data");

								SuperFriendsBean mSuperFriends = JsonUtils.parse(
										mDataObject.substring(1, mDataObject.length() - 1),
										SuperFriendsBean.class);

								return mSuperFriends;
							} else {
								return null;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					} 
				} catch(Exception e) {

				}
				return null;		

			}

			@Override
			protected void onPostExecute(SuperFriendsBean result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}


	//type 0是用户 1是企业
	//key 电话 
	//
	public void searchUser(final Context context , final String key, final int type, final int userid, final double lat, final double lng, final ResultReceiver<SuperFriendsBean> result_receiver) {
		new AsyncTask<Void, Void, SuperFriendsBean>() {
			@Override
			protected SuperFriendsBean doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_lat", lat);
						jsonObject.put("i_lng", lng);
						jsonObject.put("i_type", type);
						jsonObject.put("i_userid", userid);
						jsonObject.put("i_key", key);

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					JSONObject mJSONObject = mIo.searchUser(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {
								String mDataObject = mJSONObject.getString("Data");
								if(mDataObject.length() > 4) {
									SuperFriendsBean mSuperFriends = JsonUtils.parse(
											mDataObject.substring(1, mDataObject.length() - 1),
											SuperFriendsBean.class);

									return mSuperFriends;
								} else {
									return null;
								}
							} else {
								return null;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					} 
				} catch(Exception e) {

				}
				return null;		

			}

			@Override
			protected void onPostExecute(SuperFriendsBean result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}




	public void addShareZan(final Context context ,final int userid, final int shareid, final ResultReceiver<ZanResult> result_receiver) {
		new AsyncTask<Void, Void, ZanResult>() {
			@Override
			protected ZanResult doInBackground(Void... params) {
				try {
					JSONObject jsonObject = getBaseParams(context);
					try {
						jsonObject.put("i_shareid", shareid);
						jsonObject.put("i_userid", userid);
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

					JSONObject mJSONObject = mIo.addShareZan(jsonObject.toString());
					if(mJSONObject != null) {
						try {
							if(mJSONObject.getInt("Code") == 0) {

								return ZanResult.SUCCESS;
							} else {
								return ZanResult.Zan_UNAVAILABLE;	
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
					}
				} catch(Exception e) {

				}
				return ZanResult.IO_ERROR;		

			}

			@Override
			protected void onPostExecute(ZanResult result) {
				result_receiver.onResult(true, result);
			}
		}.execute((Void)null);
	}

	/**
	 * 获取基础的参数
	 * 
	 * @param context
	 * @return
	 */
	public static JSONObject getBaseParams(Context context) {
		JSONObject json = new JSONObject();
		try {
			UserBean u = BaseActivity.getUser(context);
			if (u == null) {
				json.put("i_userid", 0);
			} else {
				json.put("i_userid", u.getUserid());
			}

			json.put("i_lng", AppContext.lng);
			json.put("i_lat", AppContext.lat);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public void setConnected(boolean connected) {
		mIsConnected = connected;
		//		Log.i("je passe en ", connected + "");
		/*mHandler.post(new Runnable() {
			@Override
			public void run() {	
				//				Toast.makeText(mContext, mIsConnected + "", Toast.LENGTH_LONG).show();	
			}
		});*/


	}
	public boolean isDisconnectWithFaultAuthentification() {
		return mDisconnectWithFaultAuthentification;
	}

	public void setContext(Context context) {
		mContext  = context;
	}

	public boolean isConnected() {
		return mIsConnected;
	}

	public boolean isOffline() {
		return mOffline;
	}

	public boolean isAuthenticated() {
		return mAuthenticated;
	}

	public void setLoginPasswordNickname(String login, String password, String nickName) {
		mLogin = login;
		mPassword = password;
		mNickname = nickName;
	}

	public void setLoginPassword(String login, String password) {
		mLogin = login;
		mPassword = password;
	}

	public String getLogin() {
		return mLogin;
	}

	public String getPassword() {
		return mPassword;
	}

	public void setOffline(boolean b) {
		// TODO Auto-generated method stub

	}


	public String getmLogin() {
		return mLogin;
	}

	public void setmLogin(String mLogin) {
		this.mLogin = mLogin;
	}

	public String getmPassword() {
		return mPassword;
	}

	public void setmPassword(String mPassword) {
		this.mPassword = mPassword;
	}

	public String getmNickname() {
		return mNickname;
	}

	public void setmNickname(String mNickname) {
		this.mNickname = mNickname;
	}

	public String getmAvatar() {
		return mAvatar;
	}

	public void setmAvatar(String mAvatar) {
		this.mAvatar = mAvatar;
	}

	public String getmUid() {
		return mUid;
	}

	public void setmUid(String mUid) {
		this.mUid = mUid;
	}

	public static Session getsSession() {
		return sSession;
	}

	public static void setsSession(Session sSession) {
		Session.sSession = sSession;
	}

	public IO getmIo() {
		return mIo;
	}

	public void setmIo(IO mIo) {
		this.mIo = mIo;
	}

	public boolean ismIsConnected() {
		return mIsConnected;
	}

	public void setmIsConnected(boolean mIsConnected) {
		this.mIsConnected = mIsConnected;
	}

	public Context getmContext() {
		return mContext;
	}

	public void setmContext(Context mContext) {
		this.mContext = mContext;
	}

	/*public Handler getmHandler() {
		return mHandler;
	}

	public void setmHandler(Handler mHandler) {
		this.mHandler = mHandler;
	}
	 */
	public boolean ismAuthenticated() {
		return mAuthenticated;
	}

	public void setmAuthenticated(boolean mAuthenticated) {
		this.mAuthenticated = mAuthenticated;
	}

	public boolean ismDisconnectWithFaultAuthentification() {
		return mDisconnectWithFaultAuthentification;
	}

	public void setmDisconnectWithFaultAuthentification(
			boolean mDisconnectWithFaultAuthentification) {
		this.mDisconnectWithFaultAuthentification = mDisconnectWithFaultAuthentification;
	}
}